From a062ec6d7dec363e5239a2037ecdc448deab95c8 Mon Sep 17 00:00:00 2001 From: robertl Date: Tue, 15 Mar 2005 15:09:17 +0000 Subject: [PATCH] Add (sketchy) support for Keyhole Markup Language. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@1075 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/Makefile | 2 +- gpsbabel/kml.c | 216 ++++++++++++++++++++++++++++++++++++++++++++++ gpsbabel/vecs.c | 7 ++ 3 files changed, 224 insertions(+), 1 deletion(-) create mode 100644 gpsbabel/kml.c diff --git a/gpsbabel/Makefile b/gpsbabel/Makefile index cb2137150..6c8849f59 100644 --- a/gpsbabel/Makefile +++ b/gpsbabel/Makefile @@ -27,7 +27,7 @@ FMTS=magproto.o gpx.o geo.o mapsend.o mapsource.o garmin_tables.o \ gpilots.o saroute.o navicache.o psitrex.o geoniche.o delgpl.o \ ozi.o nmea.o text.o html.o palmdoc.o netstumbler.o hsa_ndv.o \ igc.o brauniger_iq.o shape.o hiketech.o glogbook.o coastexp.o \ - vcf.o overlay.o google.o lowranceusr.o + vcf.o overlay.o kml.o google.o lowranceusr.o FILTERS=position.o duplicate.o arcdist.o polygon.o smplrout.o reverse_route.o sort.o stackfilter.o diff --git a/gpsbabel/kml.c b/gpsbabel/kml.c new file mode 100644 index 000000000..1a216ecce --- /dev/null +++ b/gpsbabel/kml.c @@ -0,0 +1,216 @@ +/* + Support for Keyhole "kml" format. + + STATUS: 03/15/2005 - This file is kind of sketchy and was based + on examining sample KML data files found on the net. I do now + have the full formal spec from Keyhole, but have not revisited + this file with that information yet. I'm checking it in becuase + there have been a couple of requests for KML support. RJL + + + Copyright (C) 2005 Robert Lipe, robertlipe@usa.net + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA + + */ +#include "defs.h" +#include "xmlgeneric.h" + +static char *deficon = NULL; + +static waypoint *wpt_tmp; + +FILE *fd; +FILE *ofd; + +static +arglist_t kml_args[] = { + {"deficon", &deficon, "Default icon name", NULL, ARGTYPE_STRING }, + {0, 0, 0, 0, 0} +}; + +#define MYNAME "kml" + +#if NO_EXPAT +void +kml_rd_init(const char *fname) +{ + fatal(MYNAME ": This build excluded KML support because expat was not installed.\n"); +} + +void +kml_read(void) +{ +} +#else + +static xg_callback wpt_s, wpt_e; +static xg_callback wpt_name, wpt_desc, wpt_coord; + +static +xg_tag_mapping kml_map[] = { + { wpt_s, cb_start, "/Folder/Placemark" }, + { wpt_e, cb_end, "/Folder/Placemark" }, +// { wpt_name_s, cb_start, "/Folder/Placemark/name" }, + { wpt_name, cb_cdata, "/Folder/Placemark/name" }, + { wpt_desc, cb_cdata, "/Folder/Placemark/description" }, +// { wpt_type, cb_cdata, "/Folder/Placemark/type" }, +// { wpt_link_s, cb_start, "/Folder/Placemark/link" }, +// { wpt_link, cb_cdata, "/Folder/Placemark/link" }, + { wpt_coord, cb_cdata, "/Folder/Placemark/Point/coordinates" }, + { NULL, 0, NULL } +}; + +void wpt_s(const char *args, const char **unused) +{ + wpt_tmp = waypt_new(); +// wpt_tmp = xcalloc(sizeof(*wpt_tmp), 1); +} + +void wpt_e(const char *args, const char **unused) +{ + waypt_add(wpt_tmp); +} + +#if 0 +void wpt_name_s(const char *args, const char **attrv) +{ + const char **avp = &attrv[0]; + while (*avp) { + if (0 == strcmp(avp[0], "id")) { + wpt_tmp->shortname = xstrdup(avp[1]); + } + avp+=2; + } +} +#endif + +void wpt_name(const char *args, const char **unused) +{ + if (args) wpt_tmp->shortname = xstrdup(args); +} + +void wpt_desc(const char *args, const char **unused) +{ + if (args) wpt_tmp->description = xstrappend(wpt_tmp->description, args); +} + +void wpt_coord(const char *args, const char **attrv) +{ + sscanf(args, "%lf,%lf,%lf", &wpt_tmp->longitude, &wpt_tmp->latitude, &wpt_tmp->altitude); +} + +static +void +kml_rd_init(const char *fname) +{ + xml_init(fname, kml_map); +} + +static +void +kml_read(void) +{ + xml_read(); +} +#endif + +void +kml_rd_deinit(void) +{ + xml_deinit(); +} + +void +kml_wr_init(const char *fname) +{ + ofd = xfopen(fname, "w", MYNAME); +} + +void +kml_wr_deinit(void) +{ + fclose(ofd); +} + +static void +kml_waypt_pr(const waypoint *waypointp) +{ + char *odesc; + fputs(" \n", ofd); +// write_optional_xml_entity(ofd, "\t", "name", waypointp->shortname); + write_optional_xml_entity(ofd, "\t", "name", waypointp->description); + + fprintf(ofd, "\t"); +#if 0 + if (waypointp->description) { + char *odesc = xml_entitize(waypointp->description); + fputs(odesc, ofd); + xfree(odesc); + } +#endif + if (waypointp->url) { + char * odesc = xml_entitize(waypointp->url); + fputs("\n", ofd); + fputs(odesc, ofd); + xfree(odesc); + } + fprintf(ofd, "\n\t\n"); +// write_optional_xml_entity(ofd, "\t", "description", waypointp->description); + fprintf(ofd, "\troot://styleMaps#default?iconId=0x400\n"); + fprintf(ofd, "\t\n"); + fprintf(ofd, "\t\t%f,%f,%f\n", + waypointp->longitude, waypointp->latitude, waypointp->altitude == unknown_alt ? 0.0 : waypointp->altitude); + fprintf(ofd, "\t\n"); +#if 0 + fprintf(ofd, "", + waypointp->latitude, + waypointp->longitude); + fprintf(ofd, "\n"); + + if (waypointp->icon_descr) { + fprintf(ofd, "%s\n", deficon ? deficon : waypointp->icon_descr); + } + if (waypointp->url) { + tmp = xml_entitize(waypointp->url); + fprintf(ofd, "%s\n", + tmp); + xfree(tmp); + } +#endif + fprintf(ofd, " \n"); +} + +void +kml_write(void) +{ + fprintf(ofd, "\n"); + fprintf(ofd, "\n"); + waypt_disp_all(kml_waypt_pr); + fprintf(ofd, "\n"); +} + +ff_vecs_t kml_vecs = { + ff_type_file, + FF_CAP_RW_WPT, /* Format can do RW_ALL */ + kml_rd_init, + kml_wr_init, + kml_rd_deinit, + kml_wr_deinit, + kml_read, + kml_write, + NULL, + kml_args +}; diff --git a/gpsbabel/vecs.c b/gpsbabel/vecs.c index bbc0e6430..8d9a1eeeb 100644 --- a/gpsbabel/vecs.c +++ b/gpsbabel/vecs.c @@ -74,6 +74,7 @@ extern ff_vecs_t hiketech_vecs; extern ff_vecs_t glogbook_vecs; extern ff_vecs_t vcf_vecs; extern ff_vecs_t overlay_vecs; +extern ff_vecs_t kml_vecs; extern ff_vecs_t google_vecs; static @@ -332,6 +333,12 @@ vecs_t vec_list[] = { NULL }, { + &kml_vecs, + "kml", + "Keyhole Markup Language", + NULL + }, + { &vcf_vecs, "vcard", "Vcard Output (for iPod)", -- 2.30.2